<template>
  <a-modal
    :title="`运营商业务`"
    :width="640"
    :visible="visible"
    :confirmLoading="loading"
    @ok="
      () => {
        $emit('ok')
      }
    "
    @cancel="
      () => {
        $emit('cancel')
      }
    "
  >
    <a-spin :spinning="loading">
      <a-form :form="form" v-bind="formLayout">
        <a-form-item label="业务">
          <a-select v-decorator="['opBusinessId']" placeholder="请选择" name="opBusinessId" @change="handleChange">
            <a-select-option :value="i.id" v-for="i in this.option1" :key="i.value">{{ i.name }}</a-select-option>
          </a-select>
        </a-form-item>
        <a-form-item label="工号">
          <a-select v-decorator="['opEmpId']" placeholder="请选择" name="opEmpId">
            <a-select-option :value="i.id" v-for="i in this.option" :key="i.value">{{ i.name }}</a-select-option>
          </a-select>
        </a-form-item>
        <a-form-item label="酬金" v-if="isRem">
          <a-input
            v-decorator="['remValue', { initialValue: '0' }]"
            addonAfter="元"
            placeholder="请输入酬金"
            name="remValue"
          />
        </a-form-item>
        <a-form-item label="业务手机号">
          <a-input
            v-decorator="[
              'phone',
              {
                rules: [
                  { required: true, message: '请输入电话' },
                  { pattern: /^1[3456789]\d{9}$/, message: '请输入正确的手机号码', trigger: 'blur' },
                ],
              },
            ]"
            a
            placeholder="请输入业务手机号"
            name="phone"
          />
        </a-form-item>
        <a-form-item label="身份证号">
          <a-input
            v-decorator="[
              'idCard',
              {
                rules: [
                  { required: true, message: '请输入身份证' },
                  {
                    pattern: /^[1-9]\d{5}(18|19|20)\d{2}((0[1-9])|(1[0-2]))(([0-2][1-9])|10|20|30|31)\d{3}[0-9Xx]$/,
                    message: '请输入正确的身份证',
                    trigger: 'blur',
                  },
                ],
              },
            ]"
            a
            placeholder="请输入身份证号"
            name="idCard"
          />
        </a-form-item>
        <a-form-item label="金额">
          <a-input
            v-decorator="['amount', { initialValue: '0' }]"
            addonAfter="元"
            placeholder="请输入售价"
            name="amount"
          />
        </a-form-item>
      </a-form>
    </a-spin>
  </a-modal>
</template>
          
<script>
import pick from 'lodash.pick'
import { getOpEmpNoListUsingGET, getOpBusinessListUsingPOST1 } from '@/api/api/qiantaizhangwu.ts'
// 表单字段
const fields = ['description', 'id']

export default {
  props: {
    visible: {
      type: Boolean,
      required: true,
    },
    loading: {
      type: Boolean,
      default: () => false,
    },
    model: {
      type: Object,
      default: () => null,
    },
  },
  data() {
    this.formLayout = {
      labelCol: {
        xs: { span: 24 },
        sm: { span: 7 },
      },
      wrapperCol: {
        xs: { span: 24 },
        sm: { span: 13 },
      },
    }
    return {
      sp: true,
      yys: true,
      AA: true,
      isRem:false,
      queryParam: {
        pageNo: 1,
        pageSize: 999,
        queryCondition: '',
        status: 1,
      },
      option: [],
      option1: [],
      form: this.$form.createForm(this),
    }
  },
  created() {
    this.handle()
    this.handle1()
    // 防止表单未注册
    fields.forEach((v) => this.form.getFieldDecorator(v))

    // 当 model 发生改变时，为表单设置值
    this.$watch('model', () => {
      this.model && this.form.setFieldsValue(pick(this.model, fields))
    })
  },
  methods: {
    handle(operId) {
      getOpEmpNoListUsingGET({ ...this.queryParam, operId: operId })
        .then((res) => {
          this.option = res.data.list
        })
        .catch((error) => {
          this.$message.error(((error.response || {}).data || {}).msg || '请求出现错误')
        })
    },
    handle1() {
      getOpBusinessListUsingPOST1(this.queryParam)
        .then((res) => {
          this.option1 = res.data.list
        })
        .catch((error) => {
          this.$message.error(((error.response || {}).data || {}).msg || '请求出现错误')
        })
    },
    handleChange(e) {
      this.handle(this.option1.find((item) => item.id == e).operId)
      if(this.option1.find((item) => item.id == e).remType == 1){
        this.isRem = true
      }else{
        this.isRem = false
      }
    },
  },
}
</script>